home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / libdeflt / default.c next >
Encoding:
C/C++ Source or Header  |  1998-11-30  |  2.1 KB  |  102 lines

  1. /* @(#)default.c    1.2 98/12/01 Copyright 1997 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)default.c    1.2 98/12/01 Copyright 1997 J. Schilling";
  5. #endif
  6. /*
  7.  *    Copyright (c) 1997 J. Schilling
  8.  */
  9. /*
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include <mconfig.h>
  26. #include <stdio.h>
  27. #include <strdefs.h>
  28. #include <deflts.h>
  29.  
  30. #define    MAXLINE    512
  31.  
  32. static    FILE    *dfltfile    = (FILE *)NULL;
  33.  
  34. int
  35. defltopen(name)
  36.     const char    *name;
  37. {
  38.     if (dfltfile != (FILE *)NULL)
  39.         fclose(dfltfile);
  40.  
  41.     if (name == (char *)NULL) {
  42.         dfltfile = NULL;
  43.         return (0);
  44.     }
  45.  
  46.     if ((dfltfile = fopen(name, "r")) == (FILE *)NULL) {
  47.         return (-1);
  48.     }
  49.     return (0);
  50. }
  51.  
  52. int
  53. defltclose()
  54. {
  55.     int    ret;
  56.  
  57.     if (dfltfile != (FILE *)NULL) {
  58.         ret = fclose(dfltfile);
  59.         dfltfile = NULL;
  60.         return (ret);
  61.     }
  62.     return (0);
  63. }
  64.  
  65. char *
  66. defltread(name)
  67.     const char    *name;
  68. {
  69.     register int    len;
  70.     register int    namelen;
  71.     static     char    buf[MAXLINE];
  72.  
  73.     if (dfltfile == (FILE *)NULL) {
  74.         return ((char *)NULL);
  75.     }
  76.     namelen = strlen(name);
  77.  
  78.     rewind(dfltfile);
  79.     while (fgets(buf, sizeof(buf), dfltfile)) {
  80.         len = strlen(buf);
  81.         if (buf[len-1] == '\n') {
  82.             buf[len-1] = 0;
  83.         } else {
  84.             return ((char *)NULL);
  85.         }
  86.         if (strncmp(name, buf, namelen) == 0) {
  87.             return (&buf[namelen]);
  88.         }
  89.     }
  90.     return ((char *)NULL);
  91. }
  92.  
  93. int
  94. defltcntl(cmd, flags)
  95.     int    cmd;
  96.     int    flags;
  97. {
  98.     int  oldflags = 0;
  99.  
  100.     return (oldflags);
  101. }
  102.